package anthology.daily_question._24_11;

import java.util.Arrays;

//https://leetcode.cn/problems/friends-of-appropriate-ages/description/?envType=daily-question&envId=2024-11-17
public class _0825适龄的朋友 {
    public int numFriendRequests(int[] ages) {
        int n = ages.length;
        Arrays.sort(ages);
        int ans = 0, left = 0, right = 0;
        for(int age : ages){
            if(age < 15)
                continue;
            while(ages[left] <= 0.5 * age + 7)
                left++;
            while (right + 1 < n && ages[right + 1] <= age)
                right++;
            ans += right - left;
        }
        return ans;
    }
}
